<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Logistik_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
		
	}
	
	function getLogistik($query=FALSE,$id=FALSE,$limit=FALSE,$offset=FALSE,$log_id=FALSE,$prov_id=FALSE)
	{
		if (!$query):
			$this->db->where('logistik_id',$id);
			return $this->db->get('tb_logistik')->row();
		elseif($query=='all'):
			$this->db->limit($limit,$offset);
			$this->db->join('tb_logistik','tb_logistik_kirim.logistik_id = tb_logistik.logistik_id','left outer');
			$this->db->join('tb_kec','tb_logistik_kirim.kec_id = tb_kec.kec_id','left outer');
			$this->db->join('tb_kab','tb_kab.kab_id = tb_kec.kab_id','left outer');
			$this->db->join('tb_province','tb_province.prov_id = tb_kab.prov_id','left outer');
			$this->db->order_by('tb_logistik_kirim.logistik_kirim_id','desc');
			return $this->db->get('tb_logistik_kirim')->result_array();
		elseif($query=='where'):
			if($prov_id != 0):
				$this->db->limit($limit,$offset);
				$this->db->join('tb_logistik','tb_logistik_kirim.logistik_id = tb_logistik.logistik_id','left outer');
				$this->db->join('tb_kec','tb_logistik_kirim.kec_id = tb_kec.kec_id','left outer');
				$this->db->join('tb_kab','tb_kab.kab_id = tb_kec.kab_id','left outer');
				$this->db->join('tb_province','tb_province.prov_id = tb_kab.prov_id','left outer');
				$this->db->where('tb_logistik_kirim.logistik_id',$log_id);
				$this->db->where('tb_province.prov_id',$prov_id);
				$this->db->order_by('tb_logistik_kirim.logistik_kirim_id','desc');
				return $this->db->get('tb_logistik_kirim')->result_array();
			else:
				$this->db->limit($limit,$offset);
				$this->db->join('tb_logistik','tb_logistik_kirim.logistik_id = tb_logistik.logistik_id','left outer');
				$this->db->join('tb_kec','tb_logistik_kirim.kec_id = tb_kec.kec_id','left outer');
				$this->db->join('tb_kab','tb_kab.kab_id = tb_kec.kab_id','left outer');
				$this->db->join('tb_province','tb_province.prov_id = tb_kab.prov_id','left outer');
				$this->db->where('tb_province.prov_id',$prov_id);
				$this->db->order_by('tb_logistik_kirim.logistik_kirim_id','desc');
				return $this->db->get('tb_logistik_kirim')->result_array();
			endif;
		endif;
	}

	function addLogistik($data)
	{
		$this->db->insert('tb_logistik_kirim',$data);
	}

	function editLogistik($id,$data)
	{
		$this->db->where('logistik_kirim_id',$id);
		$this->db->update('tb_logistik_kirim',$data);
	}

	function deleteLogistik($id){
		$this->db->where('logistik_kirim_id',$id);
		$this->db->delete('tb_logistik_kirim');
	}
	
}

